package interaction;

import handlers.TeleportHandler;
import java.util.ArrayList;
import ai.AI;
import ai.BattleAI;
import loadsave.Memento;
import loadsave.loadsaveobject.LoadSaveObject;
import map.*;
import entity.BattleNPC;

public class AttackIC extends InteractionCommand {
    
    private ArrayList<BattleNPC> enemyList;
    
    public AttackIC() {
    	enemyList = new ArrayList<BattleNPC>();
    }
    
    public AttackIC( String msg ) {
        super(msg);
        enemyList = new ArrayList<BattleNPC>();
    }
    
    /**
     * execute when the user chooses this command
     * send the avatar to the battle map, along with some enemies
     */
    public void execute() {
        System.out.println("Go to combat arena");
        
        TeleportHandler t = new TeleportHandler("map_combat", GameWorld.getInstance().getAvatar());
        t.teleport();
    
    	GameMap map = GameWorld.getInstance().getMap("map_combat");
        for(BattleNPC npc : enemyList) {
            System.out.println(npc.getName());
        	AI ai = new BattleAI(GameWorld.getInstance().getAvatar());
        	map.addEntity(npc, npc.getPosition());
        	map.addAI(ai, npc);
        }
        map.initializeAI();
    }
    
    /**
     * mutator for the enemies to spawn when the avatar is sent to the corresponding battle map
     * @param enemies
     */
    public void setSpawningEnemies(ArrayList<BattleNPC> enemies) {
        enemyList = enemies;
    }

	@Override
	public Memento getMemento() {
		return new Memento() {

			@Override
			public LoadSaveObject getState() {
				LoadSaveObject toReturn = AttackIC.super.getMemento().getState();
				toReturn.setType("AttackIC");
				return toReturn;
			}

			@Override
			public void restoreState(LoadSaveObject lso) {
				AttackIC.super.getMemento().restoreState(lso);
			}
			
		};
	}

	@Override
	public AttackIC clone() {
		return new AttackIC(getID());
	}

}
